import { createAction } from 'redux-actions'
import { INIT_VERIFY_CODE_LOGIN_TYPE, UPDATE_VERIFY_CODE_LOGIN_TYPE } from './type'

import { getAuthSmsCode } from 'src/utils/RequestAPI'
/* sync */
/**
 * 初始化信息
 */
export const INIT_VERIFY_CODE_LOGIN_ACTION = createAction(INIT_VERIFY_CODE_LOGIN_TYPE, payload => payload)
/**
 * 更新信息
 */
export const UPDATE_VERIFY_CODE_LOGIN_ACTION = createAction(UPDATE_VERIFY_CODE_LOGIN_TYPE, payload => payload)

/* async */
export const DO_REQUEST_AUTH_SMSCODE_ACTION = createAction(UPDATE_VERIFY_CODE_LOGIN_TYPE, (args) => {
  return new Promise((resolve, reject) => {
    getAuthSmsCode({ params: args }).then(res => {
      console.info(res)
      // resolve()
      resolve({
        code: res.data.vcode
      })
    }).catch(() => {
      reject()
    })
  })
})
